<?php

// 本类由系统自动生成，仅供测试用途
class BookgoodsAction extends Action {

    public function index() {
        $db = M('goods');
        $goodsList = $db->select();
        $this->assign('goodsList', $goodsList);
        $this->display();
    }

    public function book_goods() {
        foreach ($_POST['goodsname'] as $cval) {
            $goodsnameArray[]= $cval;
        }
        foreach ($_POST['goodsprice'] as $cval) {
            $goodspriceArray[]=$cval;
        }
        foreach ($_POST['goodsnum'] as $cval) {
            $goodsnumArray[]=$cval;
        }
        foreach ($_POST['goodsmoney'] as $cval) {
            $goodsmoneyArray[]=$cval;
        }
        foreach ($_POST['goodsremark'] as $cval) {
            $goodsremarkArray[]=$cval;
        }        
        for ($i = 0; $i < count($goodsnameArray); $i++) {
            $orderArray['order'][]= array(
                'goodsname' => $goodsnameArray[$i],
                'goodsprice' => $goodspriceArray[$i],
                'goodsnum' => $goodsnumArray[$i],
                'goodsmoney' => $goodsmoneyArray[$i],
                'goodsremark' => $goodsremarkArray[$i]
            );
        }
        $orderArray['total'] = $_POST['total'];
        $orderArrayJson = json_encode($orderArray);
        $order = M('goodsorder');
        $data['userid'] = $_SESSION['uid'];
        $data['orderdetail'] = $orderArrayJson;
        $data['ordertime'] = date('Y-m-d H:i:s');
        if ($order->add($data)) {
            $this->success('订单提交成功！');
        } else {
            $this->error('订单提交失败！');
        }
    }

}